package org.oauth.server.authentication.oidc;

import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
import org.springframework.security.oauth2.server.authorization.oidc.authentication.OidcUserInfoAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
import org.springframework.util.Assert;

/**
 * @author Rommel
 * @version 1.0
 * @date 2023/8/12-0:59
 * @description TODO
 */
public class MyOidcUserInfoAuthenticationToken extends OidcUserInfoAuthenticationToken {
    private static final long serialVersionUID;
    private final Authentication principal;
    private final MyOidcUserInfo userInfo;

    public MyOidcUserInfoAuthenticationToken(Authentication principal) {
        super(principal);
        Assert.notNull(principal, "principal cannot be null");
        this.principal = principal;
        this.userInfo = null;
        this.setAuthenticated(false);
    }

    public MyOidcUserInfoAuthenticationToken(Authentication principal, MyOidcUserInfo userInfo) {
        super(principal,userInfo);
        Assert.notNull(principal, "principal cannot be null");
        Assert.notNull(userInfo, "userInfo cannot be null");
        this.principal = principal;
        this.userInfo = userInfo;
        this.setAuthenticated(true);
    }

    public Object getPrincipal() {
        return this.principal;
    }

    public Object getCredentials() {
        return "";
    }

    public OidcUserInfo getUserInfo() {
        return this.userInfo;
    }

    static {
        serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
    }
}
